package com.shop.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.admin.dao.AdminDao;
import com.admin.domain.ItemCommand;
import com.member.domain.MemberCommand;
import com.shop.domain.BuyCommand;
import com.shop.domain.CartCommand;

@Controller
public class MyItemBuyController {

	@Autowired
	private AdminDao adminDao;
	
	@RequestMapping("/shop/myItemBuy.do")
	public String process(CartCommand cart){
		
		String a = Long.toString(System.currentTimeMillis())+(int)(Math.random()*50);
		String b_code = a.substring(7, 14);
		BuyCommand buy = new BuyCommand();
		
		MemberCommand member = new MemberCommand();
		member.setM_id(cart.getM_id());

		ItemCommand item = new ItemCommand();
		item.setI_no(cart.getI_no());

		buy.setCartCommand(cart);
		
		buy.setB_amount(cart.getC_ea()*cart.getI_price());
		
		buy.setMemberCommand(member);
		buy.setItemCommand(item);
		buy.setB_code(b_code);
		
		adminDao.insertBuyItem(buy);
		
		return "redirect:/shop/shopMain.do";
	} 
	
}
